package com.fzkj.str;

import java.io.UnsupportedEncodingException;

/**
 * 字符串拼接
 */
public class Str {

    public static void main(String[] args) throws UnsupportedEncodingException {
//        String str1 = "hello";
//        String str2 = "wolrd";
//
//        byte[] bytes = {1, 2, 3, 4, 5, 8};
//
//        List<Integer> numbers = Arrays.asList(4, 12, 2, 32, 0, 4, 0, 71, 162, 5, 15, 62);
//        String collect = numbers.stream().map(str -> Integer.toHexString(str)).collect(Collectors.joining());
//        System.out.println(collect);

        String ip = "127.0.0.1";
        String[] length = ip.split("\\.");

        int clientId = Integer.parseInt(length[length.length - 1]);
        System.out.println(clientId);


        // 使用"+"号连接字符串
//        long startTime = System.currentTimeMillis();
//        System.out.println("开始执行时间："+ startTime);
//        for (int i = 0; i < 100000; i++) {
//            String str = str1 + str2;
//        }
//        long stopTime = System.currentTimeMillis();
//        System.out.println("结束执行时间："+ stopTime);
//        System.out.println("执行100000次字符串拼接总共耗时："+(stopTime - startTime)+"ms");

        // 使用concat连接字符串
//        String concat = str1.concat(str2);
//        long startTime = System.currentTimeMillis();
//        System.out.println("开始执行时间："+ startTime);
//        for (int i = 0; i < 100000; i++) {
//            String str = str1.concat(str2);
//        }
//        long stopTime = System.currentTimeMillis();
//        System.out.println("结束执行时间："+ stopTime);
//        System.out.println("执行100000次字符串拼接总共耗时："+(stopTime - startTime)+"ms");
//        System.out.println("连接之后的字符串："+concat);



//        StringBuffer sb = new StringBuffer();
//        long startTime = System.currentTimeMillis();
//        System.out.println("开始执行时间："+ startTime);
//        for (int i = 0; i < 100000; i++) {
//            sb.append(str1).append(str2);
//        }
//        long stopTime = System.currentTimeMillis();
//        System.out.println("结束执行时间："+ stopTime);
//        System.out.println("StringBuffer执行100000次字符串拼接总共耗时："+(stopTime - startTime)+"ms");
//
//        StringBuilder sb1 = new StringBuilder();
//        long startTime1 = System.currentTimeMillis();
//        System.out.println("开始执行时间："+ startTime1);
//        for (int i = 0; i < 100000; i++) {
//            sb1.append(str1).append(str2);
//        }
//        long stopTime1 = System.currentTimeMillis();
//        System.out.println("结束执行时间："+ stopTime1);
//        System.out.println("StringBuilder执行100000次字符串拼接总共耗时："+(stopTime1 - startTime1)+"ms");



//        StringBuilder sb = new StringBuilder();
//        long startTime = System.currentTimeMillis();
//        for (int i = 0; i < 1000000; i++) {
//            sb.append(str1).append(str2);
//        }
//        long stopTime = System.currentTimeMillis();
//        System.out.println("StringBuilder拼接100次耗时："+(stopTime - startTime)+"ms");
//
//
//        long startTime1 = System.currentTimeMillis();
//        for (int i = 0; i < 1000000; i++) {
//            str1.concat(str2);
//        }
//        long stopTime1 = System.currentTimeMillis();
//        System.out.println("concat拼接100次耗时："+(stopTime1 - startTime1)+"ms");




    }

}
